package org.light.easyuilayouts;

import java.util.ArrayList;
import java.util.List;

import org.light.core.Writeable;
import org.light.domain.Domain;
import org.light.domain.StatementList;
import org.light.easyuilayouts.widgets.OracleEnumMainDatagrid;
import org.light.easyuilayouts.widgets.SearchPanel;
import org.light.easyuilayouts.widgets.ViewDialog;
import org.light.exception.ValidateException;
import org.light.utils.WriteableUtil;

public class OracleEasyUIEnumGridPageLayout extends EasyUIEnumGridPageLayout{
	protected OracleEnumMainDatagrid mainDatagrid;
	
	public OracleEasyUIEnumGridPageLayout(Domain domain){
		super(domain);
	}

	@Override
	public StatementList generateLayoutStatements() throws ValidateException {
		List<Writeable> sList = new ArrayList<>();
		StatementList sl1 = searchPanel.generateWidgetStatements();
		if (sl1!=null) sl1.setSerial(4000L);
		StatementList sl2 = mainDatagrid.generateWidgetStatements();
		if (sl2!=null) sl2.setSerial(5000L);
		StatementList sl5 = viewDialog.generateWidgetStatements();
		if (sl5!=null)  sl5.setSerial(8000L);
		if (sl1!=null) sList.add(sl1);
		if (sl2!=null) sList.add(sl2);
		if (sl5!=null) sList.add(sl5);		
		
		StatementList rsl = WriteableUtil.merge(sList);
		rsl.setSerial(this.serial);
		return rsl;
	}

	@Override
	public StatementList generateLayoutScriptStatements() throws ValidateException{
		List<Writeable> sList = new ArrayList<>();
		StatementList sl1 = mainDatagrid.generateWidgetScriptStatements();
		sl1.setSerial(1000L);
		sl1.setIndent(1);
		sList.add(sl1);
		
		StatementList rsl = WriteableUtil.merge(sList);
		rsl.setSerial(this.serial);
		return rsl;
	}

	@Override
	public boolean parse() {
		if (this.domain!=null) {
			this.searchPanel = new SearchPanel();
			this.mainDatagrid = new OracleEnumMainDatagrid();
			this.viewDialog = new ViewDialog();

			this.searchPanel.setDomain(this.domain);
			this.mainDatagrid.setDomain(this.domain);
			this.viewDialog.setDomain(this.domain);

			return true;
		}
		return false;
	}

	public OracleEnumMainDatagrid getMainDatagrid() {
		return mainDatagrid;
	}

	public void setMainDatagrid(OracleEnumMainDatagrid mainDatagrid) {
		this.mainDatagrid = mainDatagrid;
	}

}
